home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7429 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: american.edu!JW1675A
  2. From: JW1675A@american.edu (James D. Watson)
  3. Newsgroups: comp.lang.c
  4. Subject: more problems with qsort
  5. Date: Mon, 26 Feb 96 10:44:18 EST
  6. Organization: The American University
  7. Message-ID: <177399702S86.JW1675A@american.edu>
  8. NNTP-Posting-Host: auvm.american.edu
  9.  
  10. Hi folks --
  11.  
  12. after reading the FAQ entries about qsort, I thought I had my problem
  13. licked, but it seems not.
  14.  
  15. Architecture: SunOS 4.1.3 with ANSI-C compiler.
  16.  
  17. I'm doing some file manipulation and between steps A and B, I need to sort.
  18. For various reasons, I don't want to popen() to the sort utility--I want to
  19. use qsort.  Here's what I'm doing:
  20.  
  21.    get number of lines in the file
  22.    (char**)malloc with enough room for all lines
  23.    for each line in the file {
  24.      (char*)malloc(90)  /* 90 is enough room for each line in file */
  25.      copy each line into the newly malloc()ed space
  26.      point a (char**) to the newly malloc()ed space
  27.    }
  28.  
  29. so now I should have "lines" number of pointers to pointers to char,
  30. each one pointing to 90 bytes containing a line in the file.
  31.  
  32. So, I call qsort(array[0], lines, 90, compare)
  33. where compare is my comparison function -- prepared as discussed
  34. in the FAQ.  Now all I get are core dumps during the call to qsort().
  35. :-)
  36.  
  37. The core dump isn't in my compare routine -- it's somewhere else in
  38. the qsort() function according to dbx -- so I'm sure it's a problem
  39. setting up my data.
  40.  
  41. Any tips?  Much appreciation in advance,
  42. Regards,
  43. Jim
  44.